#pragma once

#include <iostream>
#include <map>

using namespace  std;

#include "String.hh"

using namespace  mtool;

#include "HttpRequest.hh"
#include "ByteBuffer.hh"

static inline void trim(string & s){
        int begin=0;
        char str[s.size()];
        if(s[0]==' ')
            for(int i=0;i<s.size();i++){
                if(s[i]!=' '){   memmove(&(s[0]),&(s[i]),s.size()-i);printf("%d\n",i);break;}
            }

}

class tcpimpl{
	public:	
		bool handle( char * instr,size_t len,ByteBuffer & out);
};


class httpimpl{
	public:	
		bool handle( char * instr,size_t len,ByteBuffer & out);
	private:
		void next();
};



/*
 * ref :  http://tool.oschina.net/commons
 * */




class httpResponse{
    private:
	std::string version;
	std::string status_code;
	std::string reason_phrase;
	map<std::string,std::string> headers;
	vector<std::string  > sendfiles;  //will send file's name
	void setHead(const std::string  &key,const std::string &val);
	std::string getDateStr(size_t second);  //Sat, 31 Dec 2005 23:59:59 GMT
	std::string  rsphead;   
	int extfd=-1;
//	std::string content;

    public:
    	static const std::string  APPLICATION_OCTET_STREAM; 
    	static const std::string  APPLICATION_JAVASCRIPT;   // application/x-javascript
    	static const std::string  TEXT_CSS;   // text/css
    	static const std::string  TEXT_HTML;   // text/css
	static const std::string  IMAGE_X_ICON;		// image/x-icon
	static const std::string  IMAGE_PNG;		// image/png
	static const std::string  IMAGE_JPEG;		// image/jpeg

	httpResponse();
	void setContentType(std::string type);
	void setContentLength(size_t  len);
	std::string generator();
	bool  setTxt(const std::string &filename);
	bool setDataFile(const std::string &filename);


};

//std::string httpResponse::APPLICATION_OCTET_STREAM="application/octet-stream";


class httpCookies{
    private:
	std::string key;
	std::string val;
	std::string path;
	std::string expires;
	bool httpOnly;

    public:


};

 extern const map<HttpRequest::exttype, std::string> httpResponseMap ;
